package htmodels

import (
	"github.com/astaxie/beego/orm"
	"travelservia/models"
)
func HTXiangmuAdd(xiangmu *models.Xiangmu) error {
	o := orm.NewOrm()
	_, err := o.Insert(xiangmu)
	return err
}

func HTXiangmuGetDetail(xiangmu *models.Xiangmu) error {
	o := orm.NewOrm()
	return o.Read(xiangmu)
}

func HTXiangmuGetCount(search string, searchFiled string , Status int) (int64, error) {
	o := orm.NewOrm()
	m := models.Xiangmu{}
	count, err := o.QueryTable(m.TableName()).Filter(m.FN_Status(), Status).Filter(searchFiled + "__icontains", search).Count()
	return count, err
}

func HTXiangmuGetList(xiangmus *[]models.Xiangmu, fields []string , Status int, offset int64, limit int, search string, searchFiled string, orderby string) error {
	o := orm.NewOrm()
	m := models.Xiangmu{}
	_, err := o.QueryTable(m.TableName()).Filter(m.FN_Status(), Status).Filter(searchFiled + "__icontains", search).OrderBy(orderby).Offset(offset).Limit(limit).All(xiangmus, fields...)
	return err
}

func HTXiangmuDelete(Ids []int64) (int64, error) {
	o := orm.NewOrm()
	m := models.Xiangmu{}
	count, err := o.QueryTable(m.TableName()).Filter("Id" + "__in", Ids).Delete()
	return count, err
}
func HTXiangmuStatusChange(Ids []int64, status int) (int64, error) {
	o := orm.NewOrm()
	m := models.Xiangmu{}
	count, err := o.QueryTable(m.TableName()).Filter("Id" + "__in", Ids).Update(orm.Params{
		m.FN_Status(): status,
	})
	return count, err
}
func HTXiangmuUpdate(xiangmu *models.Xiangmu) error {
	o := orm.NewOrm()
	_, err := o.Update(xiangmu)
	return err
}